<?php


namespace app\model;



use think\model\concern\SoftDelete;
use think\model\relation\HasMany;

class Account extends \think\Model
{

    private $userName;
    private $password;


    protected $table = 'account';
    protected $key = 'id';

    // 设置字段信息
    protected $schema = [
        'id' => 'int',
        'userName' => 'varchar',
        'password' => 'varchar',
        'phone' => 'char',
        'headerUrl' =>'varchar',
        'delete_time' => 'char'
    ];

    // 软删除
    use SoftDelete;

    protected $deleteTime = 'delete_time';


    // 加密
    public static function hashPassword(string $password): string
    {
        return password_hash($password, PASSWORD_DEFAULT);
    }

    // 验证密码
    public static function verifyPas(string $password,string $has): bool
    {

        return password_verify($password, $has);
    }

    // 一对一
    public function profile()
    {
        return $this->hasOne(Sex::class, 'uid')->bind(['gender']);
    }

    // 一对多 文章
    public function userArticle()
    {
        return $this->belongsTo(ArticleModel::class,'id','uid');
    }

    // 一对多 点赞
    public function userLike(): HasMany
    {
        return $this->hasMany(ArticleLikeModel::class, 'uid', 'id');
    }

    // 一对多 收藏
    public function userCollect(): HasMany
    {
        return $this->hasMany(ArticleCollectModel::class, 'uid', 'id');
    }
}